Imports System.Drawing

''' <summary>
''' The RegionArea object describes a region on a chart. There is one region for each distinct value in each 
''' series. Regions may overlap. The purpose of the RegionArea object is to identify which part of which 
''' series a user has clicked on, when drilling down into a chart.
''' </summary>
''' <remarks></remarks>
Public Class RegionArea
    Private msSeriesName As String
    Private moSeriesPoints() As Point
    Private moGraphicsRegion As Region
    Private msnXValue As Single
    Private msnYValue As Single

    ''' <summary>
    ''' sSeriesName is the name of the jChart.Series with which this RegionArea is associated. snXValue is the X 
    ''' value at which the region is located and snYValue is the Y value at which the region is located. 
    ''' oSeriesPoints() is an array of Point that describes a polygon surrounding the region.
    ''' </summary>
    ''' <param name="sSeriesName"></param>
    ''' <param name="snXValue"></param>
    ''' <param name="snYValue"></param>
    ''' <param name="oSeriesPoints"></param>
    ''' <remarks></remarks>
    Public Sub New( _
        ByVal sSeriesName As String, _
        ByVal snXValue As Single, _
        ByVal snYValue As Single, _
        ByVal oSeriesPoints() As Point)

        msSeriesName = sSeriesName
        moSeriesPoints = oSeriesPoints
        moGraphicsRegion = PointsToRegion()

        msnXValue = snXValue
        msnYValue = snYValue
    End Sub

    ''' <summary>
    ''' The name of the jChart.Series to which the region belongs.
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public ReadOnly Property SeriesName() As String
        Get
            Return msSeriesName
        End Get
    End Property

    ''' <summary>
    ''' An array of Point that describes a polygon surrounding the region.
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public ReadOnly Property SeriesPoints() As Point()
        Get
            Return moSeriesPoints
        End Get
    End Property

    ''' <summary>
    ''' Gets a System.Drawing.Region object that encloses the region.
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public ReadOnly Property SeriesRegion() As Region
        Get
            Return moGraphicsRegion
        End Get
    End Property

    ''' <summary>
    ''' Gets the X value at which the region is located.
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public ReadOnly Property XValue() As Single
        Get
            Return msnXValue
        End Get
    End Property

    ''' <summary>
    ''' Gets the Y value at which the region is located
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public ReadOnly Property YValue() As Single
        Get
            Return msnYValue
        End Get
    End Property

    Private Function PointsToRegion() As Region
        Dim oTypes(moSeriesPoints.GetUpperBound(0)) As Byte

        For iCurPoint As Integer = 0 To moSeriesPoints.GetUpperBound(0)
            oTypes(iCurPoint) = System.Drawing.Drawing2D.PathPointType.Line
        Next

        Dim oGPath As New System.Drawing.Drawing2D.GraphicsPath(moSeriesPoints, oTypes)
        Dim oRegion As New System.Drawing.Region(oGPath)

        Return oRegion
    End Function
End Class
